<?php
class Flashgame_Widget_PopularGamesController extends Engine_Content_Widget_Abstract
{
    public function indexAction()
    {
        if($this->_getParam('num') != ''  && $this->_getParam('num') >= 0)
        {       
            $num_games = $this->_getParam('num');
        }else
        {
            $num_games = 5;
        }
        $b_table = Engine_Api::_()->getDbtable('flashgames', 'flashgame');
        $bName = $b_table->info('name');
        $select = $b_table->select()->from($bName)  ;
        $select ->order('view_count DESC');
        $select ->where("search = ?","1");
        $select ->where("view_count > ?","0"); 
        $select->limit($num_games);
        $this->view->games = $b_table->fetchAll($select);
        $this->view->limit = $num_games;
        if (count($this->view->games) == 0)
            return $this->setNoRender();
    }
}